package com.wwwc.index.web.servlet;

import java.io.*;
import java.security.*;
import javax.servlet.http.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.ServletRequestWrapper;
import java.net.*;

import com.wwwc.util.web.*;

public class AdvServlet  extends HttpServlet {

    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
	response.setContentType("text/html");
        PrintWriter out     = response.getWriter();
	HttpSession session = request.getSession(true);
	String user_ip      = request.getRemoteAddr();

	///////////////////////////////////////////////////////////////////////////
	// user info
	///////////////////////////////////////////////////////////////////////////
	String user_name  = null;
	String user_fname = null;
	String user_since = null;
	String user_edu   = null;
	String user_zip   = null;
	String user_sex   = null;
	String screen_w   = null;
	String screen_h   = null;

	int user_age      = 0;
	int user_level    = 0;

	Hashtable user_info = (Hashtable)session.getAttribute("user_info");
	if(user_info != null) {
	    user_name  = (String)user_info.get("user_name");
	    user_fname = (String)user_info.get("user_fname");
	    user_since = (String)user_info.get("user_since");
	    user_edu   = (String)user_info.get("user_edu");
	    user_zip   = (String)user_info.get("user_zip");
	    user_sex   = (String)user_info.get("user_sex");
	    user_age   = Integer.parseInt((String)user_info.get("user_age"));
	    user_level = Integer.parseInt((String)user_info.get("user_level"));
	    screen_w   = (String)user_info.get("screen_w");
	    screen_h   = (String)user_info.get("screen_h");
	}
	else {
	    System.out.println("AdvServlet:Error:101");
	    return;
	}

	//int sw = Integer.parseInt(screen_w);
	//int sh = Integer.parseInt(screen_h);

	String url = request.getParameter("adv_url");
	String sid = request.getParameter("adv_sid");
	String pid = request.getParameter("adv_position");

	if(sid == null || pid == null) {
	    System.out.println("AdvServlet:Error:101");
	    return;
	}

	String action    = request.getParameter("aid");
	String call_path = request.getContextPath()+request.getServletPath();

	out.println(MyJavaScript.disableHistory());

	if(action == null) {
	    AdvBean abean = new AdvBean();
	    String adv_submit = (String)session.getAttribute("adv_submit");

	    if(adv_submit == null) {
		out.println(abean.advRequiredForm(request, sid, pid, call_path));
	    }
	    else {
		out.println("<BR><BR><H3>Thank you!</H3>");
		out.println(user_ip);
	    }
	    return;
	}
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
	doPost(request, response);
    }
}

